def count_words(filename):
    try:
        with open(filename, encoding='utf-8') as f:
            contents = f.read()
    except FileNotFoundError:
        pass # 如果需要在发生异常时保持静默,用pass(只能有pass)
        # print(f"Sorry, the file {filename} does not exist.")
    else:
        # 计算文件大概包含多少个单词
        words = contents.split() # split()方法把字符串以空格为分隔符拆分成一个由单词组成的列表
        num_words = len(words)
        print(f"The file {filename} has about {num_words} words.")

file_names = ['alice.txt','siddhartha.txt']
for file_name in file_names:
    count_words(file_name)